<style lang="less">
    @import "../../../styles/table.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card>
                    <Row @keydown.enter.native="handleSearch">
                        <Form ref="searchForm" :model="searchForm" inline :label-width="70">
                            <Form-item label="订单号" prop="id">
                                <Input type="text" v-model="searchForm.id" placeholder="请输入订单号" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item label="企业名称" prop="company">
                                <Input type="text" v-model="searchForm.company" placeholder="请输入企业名称" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item label="企业电话" prop="linkPhone">
                                <Input type="text" v-model="searchForm.linkPhone" placeholder="请输入企业电话" clearable style="width: 200px"/>
                            </Form-item>
                            <span v-if="drop">
                                 <!--<Form-item label="VIP类型" prop="status">
                                <Select v-model="searchForm.status" placeholder="请选择" clearable style="width: 200px">
                                    <Option value="0">黄金VIP</Option>
                                    <Option value="-1">铂金VIP</Option>
                                    <Option value="-1">钻石VIP</Option>
                                </Select>
                            </Form-item>-->
                                <Form-item label="创建时间">
                                  <DatePicker v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
                                </Form-item>
                            </span>
                            <Form-item style="margin-left:-35px;" class="br">
                                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                                <Button @click="handleReset">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row class="operation">
                        <Button @click="exportData" icon="md-trash">导出</Button>
                        <Button @click="getDataList" icon="md-refresh">刷新</Button>
                        <circleLoading v-if="operationLoading"/>
                    </Row>
                    <Row>
                        <Alert show-icon>
                            已选择 <span class="select-count">{{selectCount}}</span> 项
                            <a class="select-clear" @click="clearSelectAll">清空</a>
                        </Alert>
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>
    </div>
</template>

<script>
    import circleLoading from "../../my-components/circle-loading.vue";
    import {orderList, delOrder} from "@/api/bus";
    import Util from '@/libs/util';

    export default {
        name: "vipcomp-manage",
        components: {
            circleLoading
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "createTime", // 默认排序字段
                    order: "desc", // 默认排序方式
                    id: "",
                    orderEntity: "vip",
                    company: "",
                    targetId: 2,
                    linkPhone: "",
                    startDate: "",
                    endDate: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [
                    {
                        type: "selection",
                        width: 60,
                        align: "center"
                    },
                    {
                        type: "index",
                        width: 60,
                        align: "center"
                    },
                    {
                        title: "订单号",
                        key: "id",
                        width: 200,
                        sortable: true
                    },
                    {
                        title: "企业名称",
                        key: "company",
                        width: 200,
                        sortable: true
                    },
                    {
                        title: "联系方式",
                        key: "linkPhone",
                        width: 115,
                        sortable: true
                    },
                    {
                        title: "联系人",
                        key: "linkName",
                        width: 115,
                        sortable: true
                    },
                    {
                        title: "vip类型",
                        key: "targetId",
                        width: 180,
                        sortable: true,
                        render: (h, params) => {
                            return h("div", "企业VIP");
                        }
                    },
                    {
                        title: "支付方式",
                        key: "payTypeText",
                        width: 180,
                        sortable: true
                    },
                    {
                        title: "会员期限",
                        width: 180,
                        sortable: true,
                        render: (h, params) => {
                            return h("div", "一年");
                        }
                    },
                    {
                        title: "支付金额",
                        key: "orderAmount",
                        width: 180,
                        sortable: true
                    },
                    {
                        title: "支付日期",
                        key: "payDate",
                        width: 180,
                        sortable: true
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            init() {
                this.getDataList();
            },
            getDataList() {
                this.loading = true;
                orderList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });

            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getDataList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                // 重新加载数据
                this.getDataList();
            },
            exportData() {
                window.location.href = Util.initUrl("/base/common/download3",this.searchForm);
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            add() {

            },
            edit(v) {

            },
            remove(v) {

            },
            delAll() {

            }
        },
        mounted() {
            this.init();
        }
    }
</script>
